from appium.webdriver.common.appiumby import By
from selenium.webdriver.support.wait import WebDriverWait

from appPage.enter_homepage import EnterHomePage
from appPage.login import Login
from config import PHONE, PWD
from utils.driver_utils import DriverUtils


class SlideHomePage:
    def slide_homepage(self, driver):
        WebDriverWait(driver, 10).until(lambda x: x.find_element(by=By.ID,value="com.tpshop.malls:id/home_img")).click()
        # 滑动首页
        for i in range(3):
            driver.swipe(start_x=540, start_y=1600, end_x=540, end_y=220)
        WebDriverWait(driver, 10).until(lambda x: x.find_element(by=By.ID,value="com.tpshop.malls:id/default_to_top_img")).click()

if __name__ == '__main__':
    # 获取驱动
    driver_utils = DriverUtils()
    driver = driver_utils.get_driver()
    # 进入首页
    enter = EnterHomePage()
    enter.enter_homepage(driver)
    # 登录
    login = Login()
    login.login(driver, PHONE, PWD)
    # 滑动首页
    slide = SlideHomePage()
    slide.slide_homepage(driver)
    driver_utils.quit_driver()